package com.zzgc.modules.controller;

import com.sun.xml.internal.messaging.saaj.packaging.mime.util.LineInputStream;
import com.zzgc.modules.log.ApiLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;
import java.util.*;
import java.util.concurrent.*;

/**
 * 测试类
 * @Author:
 * @CreateTime: 2022-12-17  14:11
 * @Description:
 * @Version: 1.0
 */
@RestController
@RequestMapping("test")
@Api(tags = "测试接口")
@ApiLog(value = "测试类", url = "test")
public class TestController {

    @ApiLog(value = "登录测试", url = "login")
    @RequestMapping("login")
    @ApiOperation(value = "登录测试")
    public String login() {
        return "成功!";
    }

    public static void main1(String[] args) {
        ArrayList<Object> list1 = new ArrayList<>();
        list1.add("asss1");
        list1.add("asss2");
        list1.add("asss3");
        list1.add("asss4");
        list1.add("asss5");
        "".split(",");
        new Thread(()->{});
        //list1.addAll();
        Arrays.asList();
//        list1.add("asss6");
//        list1.add("asss7");
//        list1.add("asss8");
//        list1.add("asss9");
//        list1.add("asss10");

        List<Object> list2 = new ArrayList<>();
        double d1 = Math.ceil(list1.size() / 4.0);
        int x = (int) d1;
        for (int i = 0; i < d1; i++) {
            int form = i * 4;
            int to = form + 4;
            if (i == x - 1) {
                to = list1.size();
            }
            list2.add(list1.subList(form, to));
        }
        int skk = 4;
        double d = skk;
        System.out.println(d);
        System.out.println(list2);
        System.out.println(9^4);
        System.out.println(1<<2);
        new HashMap<>().put("", "");
        new HashSet<>().add("");
        ArrayList<Object> list = new ArrayList<>();
        list.toArray();
        System.out.println(5 == 4);
        // 分页测试
        /*List<Object> objects = new ArrayList<>();
        for (int i = 1; i < 100; i++) {
            objects.add(i);
        }
        System.out.println("objects = " + objects);
//        List<Object> page = page(objects, 2, 15);
//        System.out.println("page = " + page);
        objects = objects.subList(1, 10);
        System.out.println(objects);*/
    }

    public static List<Object> page(List<Object> list, Integer page, Integer size){
        page = (page - 1) * size;
        size = page + size;
        return list.subList(page, size);
    }

    public static void main(String[] args) {
        File file = new File("E:\\桌面\\test.txt");
        TestController testController = new TestController();
        String s = testController.readFile(file, 3, 9);
        System.out.println("s = " + s);
    }

    // 获取某行某列的值
    public String readFile(File file, Integer line, Integer column) {
        if (!file.exists() && !file.isFile()) {
            throw new RuntimeException("文件不存在或不是文件！");
        }
        BufferedReader bufferedReader = null;
        StringBuffer buffer = new StringBuffer();
        try {
            bufferedReader = new BufferedReader(new FileReader(file));
            String s1 = "";
            int count = 0;
            while ((s1 = bufferedReader.readLine()) != null && count < line){
                if (count == line - 1) {
                    if (s1.length() < column) {
                        buffer.append(" |");
                    }else {
                        buffer.append(s1.charAt(column - 1)).append("|");
                    }
                }else {
                    buffer.append("");
                }
                count++;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer.toString();
    }

}


